#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e5 + 10;
long long dp[N];
long long arr[N];
int n;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];

    dp[0] = arr[0];
    for (int i = 1; i < n;i++)
        dp[i] = max(dp[i - 1] + arr[i], arr[i]);

    cout << dp[n - 1] << endl;

    return 0;
}